package cn.vihub.controller;

import cn.vihub.param.ShopBrandInfoParam;
import cn.vihub.pojo.ShopBrandInfo;
import cn.vihub.service.ShopBrandInfoService;
import cn.vihub.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("shop-store/brandInfo")
public class ShopBrandInfoController {

    @Autowired
    private ShopBrandInfoService shopBrandInfoService;

    @GetMapping("list")
    public Result<IPage<ShopBrandInfo>> list(ShopBrandInfoParam shopBrandInfoParam){
        return Result.success(shopBrandInfoService.selectByPage(shopBrandInfoParam));
    }

    @PostMapping("save")
    public Result<Boolean> save(@RequestBody ShopBrandInfoParam shopBrandInfoParam){
        ShopBrandInfo shopBrandInfo = new ShopBrandInfo();
        BeanUtils.copyProperties(shopBrandInfoParam, shopBrandInfo);
        return Result.success(shopBrandInfoService.saveOrUpdate(shopBrandInfo));
    }

    @DeleteMapping("delete/{id}")
    public Result<Boolean> delete(@PathVariable("id") Integer id){
        return Result.success(shopBrandInfoService.removeById(id));
    }

}
